Option Explicit On

'Title:     Class Example
'Author:    Pam McCarthy  Modified by Greg Cronk
'Date:      Date Due
'Course:    CSC 162
'Section:   001 & 002
'Description:   This program demonstrates how to keep track
'               of a running total of numbers
'
'Initial Algorithm:
'   1.  Get Number Entered by User
'   2.  Add to running total
'   3.  Display running total
'
'Data Requirements:
'   Input:
'       Number entered by user:  NumEntered
'   Output:
'       Running Total (sum of all numbers entered): RunTotal
'   Additional:
'       None
'
'Formulas:
'   RunTotal = RunTotal + NumEntered
'
'Refined Algorithm:
'   1.  Get Number Entered by User
'   2.  Add to running total
'           RunTotal = RunTotal + NumEntered
'   3.  Display running total

Public Class frmRunningTotal
    Inherits System.Windows.Forms.Form

    'Global Variable Section
    Dim RunTotal As Integer 'Running Total

    Dim ClickCount As Integer 'Number of time values have been entered to the running total.

    Private Sub cmdAdd_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdAdd.Click
        'This command button adds the number entered to the running total

        'Declare local variables
        Dim NumEntered As Integer 'Number entered by user

        'Get number entered into text box and put into variable
        NumEntered = Val(txtNumEntered.Text)

        'Calculate running total
        RunTotal = RunTotal + NumEntered

        'Place new total into label
        lblRunTotal.Text = RunTotal

        'Clear out text box for next number
        txtNumEntered.Text = ""

        'Return cursor to text box for next number
        txtNumEntered.Focus()

        'Add one to the Use Count (ClickCount)
        ClickCount = ClickCount + 1

        'Calculate the Mean using the Run total and the Use Count and Disply it in txtAverage
        txtAverage.Text = RunTotal / ClickCount

    End Sub

    Private Sub cmdClear_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdClear.Click
        Dim Mean As Integer 'Average Value entered into NumEntered
        'This button clears out all text boxes
        txtNumEntered.Text = ""
        lblRunTotal.Text = ""

        'Re-initialize RunTotal
        RunTotal = 0

        'Add Counter is cleared.
        ClickCount = 0

        'Clear the Average
        Mean = 0

        'Clear the Average Display
        txtAverage.Text = ""

        'Set focus back to text box
        txtNumEntered.Focus()

    End Sub

    Private Sub cmdEnd_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEnd.Click
        'This command button ends the program
        Me.Close() 'Remove active window
        End 'End program
    End Sub

    Private Sub frmRunningTotal_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        'Initialize Text Boxes, labels, and variables to zero when form is loaded
        txtNumEntered.Text = ""
        lblRunTotal.Text = ""
        RunTotal = 0
        ClickCount = 0
        lblInfo.Text = "This program adds up numbers"
    End Sub
End Class